package com.example.util;


import com.example.atools.MyConstant;

import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
/** Description of GameOpenClass 
*
* @author DauNM
* @author 0974470610
* @version 1.0
*/
public class GameDialogExit extends Builder{
	/**
     * Open Elert Dialog Exit
     * If has link(Status=1) open dialog ask user open link
     * If no link(Status=0) open dialog ash user exit
     * context = Activity Call .this
     * @return void
     */  
	public GameDialogExit(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		final Activity activity = (Activity)context;
		if(MyConstant.mExitStatus==1){
			this.setTitle("Tải game");
		}else{
			this.setTitle("Thoát game");
		}
		this.setMessage(MyConstant.mExitMsg);
		this.setCancelable(true);
		this.setPositiveButton("Có",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						onOpenLink(activity);
						activity.finish();
						Config.IsCheck=false;
						dialog.dismiss();
					}
				});
		this.setNegativeButton("Không",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						if(MyConstant.mExitStatus==1){
							activity.finish();
							Config.IsCheck=false;
						}
						dialog.dismiss();
					}
				});
	}
	
	public static void onOpenLink(Activity activity) {
		if(MyConstant.mExitStatus==1){
			try{
				Intent intent = new Intent(Intent.ACTION_VIEW);
				intent.setData(Uri.parse(MyConstant.mExtLink));//"market://details?id=com.banga"
				activity.startActivity(intent);
			}catch(Exception ex){}
		}
	}

}
